/**   
* @Title: TaskThreadCache.java 
* @Package cn.com.gome.cashier.task.service.impl 
* @Description: 线程缓存
* @author chenmin-ds   
* @date 2016年3月28日 下午5:09:18 
* @company cn.com.gome
* @version V1.0   
*/ 


package cn.com.klun.tjy.service.Impl;

import cn.com.klun.util.BasisConstants;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/** 
 * @ClassName: TaskThreadCache 
 * @Description: 线程缓存
 * @author chenmin-ds
 * @date 2016年3月28日 下午5:09:18
 */
public class TaskThreadCache {

	private static ConcurrentMap<String, Integer> taskCount = new ConcurrentHashMap<String,Integer>();
	
	public static synchronized boolean getTaskCount(String key){
		Integer temp = taskCount.get(key);
		if(null == temp){
			taskCount.put(key, 1);
			return true;
		}else{
			if(temp.intValue() < BasisConstants.threadCount){
				taskCount.put(key, temp.intValue() + 1);
				return true;
			}else{
				return false;
			}
			
		}
	}
	
	public static synchronized void setTaskCount(String key){
		int temp = taskCount.get(key).intValue();
		if(temp > 0){
			temp--;
			taskCount.put(key, temp);
		}
	}
}
